package cn.appsys.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.appsys.pojo.BackendUser;
import cn.appsys.pojo.DevUser;
import cn.appsys.service.back.BackendUserService;
import cn.appsys.service.deve.Dev_UserService;
import cn.appsys.tools.Constants;

@Controller
//其他Controller类名前统一加 "sys"
/**
 * 用于登录，再拦截不了就把钟多雄杀了祭天
 * @author hzm
 */
public class TestController {
	@Resource
	private Dev_UserService dsi;
	@Resource
	private BackendUserService bsi;
	
	@RequestMapping("dev/login")
	public String toDev(){
		return "devlogin";
	}
	
	@RequestMapping("dev/dologin")
	public String doDev(String devCode,String devPassword,Model model,
			HttpSession session){
		DevUser devUser=dsi.login(devCode, devPassword);
		if(devUser==null){
			model.addAttribute("error","用户名或密码错误");
			return "devlogin";
		}
		session.setAttribute(Constants.USER_SESSION2, devUser);
		//移除另一种账户
		session.removeAttribute(Constants.USER_SESSION1);
		return "redirect:/sys/deve/main";
	}
	
	@RequestMapping("manager/login")
	public String toBackend(){
		return "backendlogin";
	}
	
	@RequestMapping("manager/dologin")
	public String doBack(String userCode,String userPassword,Model model,
			HttpSession session){
		BackendUser backendUser=bsi.login(userCode, userPassword);
		if(backendUser==null){
			model.addAttribute("error","用户名或密码错误");
			return "backendlogin";
		}
		session.setAttribute(Constants.USER_SESSION1, backendUser);
		//移除另一种账户
		session.removeAttribute(Constants.USER_SESSION2);
		return "redirect:/sys/back/main";
	}
}
